package chapter9.section5;

/* 程序9-10：输出捕获组匹配文本 */
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class TestCapturingGroups {
	public static void main(String[] args) {
		String regEx = "[+|-]?(\\d+ (\\.\\d*)?)|(\\.\\d+)";
		String str = "225 is the square of 15 and -3.0 square is 9.00" + "and -.123 is less than 0.1234.";
		Pattern pattern = Pattern.compile(regEx);
		Matcher matcher = pattern.matcher(str);
		while (matcher.find()) {
			for (int i = 0; i <= matcher.groupCount(); i++) {
				System.out.println("Group" + i + ":" + matcher.group(i) + "");
			}
			System.out.println();
		}
	}
}
